package cn.explink.dop.entity.vo;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.GenericGenerator;

import cn.explink.distributor.framework.AbstractOrder;
import cn.explink.dop.enums.OrderIsSettleDeliveryEnum;
import cn.explink.dop.enums.OrderPayMethodEnum;
import cn.explink.dop.enums.OrderReadyStatus;
import cn.explink.dop.enums.OrderStatusEnum;
import cn.explink.dop.enums.pub.YesNoEnum;
import cn.explink.dop.tools.Tools;

@Entity
@Table(name = "or_order")
@JsonIgnoreProperties(value = { "hibernateLazyInitializer" })
public class OrderVO extends AbstractOrder implements java.io.Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = -7472154635091258201L;

	private String id;

	/**
	 * 订单编码
	 */
	private String code;
	/**
	 * 订单名称
	 */
	private String orderName;
	/**
	 * 订单状态
	 */
	private int status;
	/**
	 * 状态改变的时间
	 */
	private Date statusChangeTime;

	/**
	 * 订单状态日志
	 */
	private String statusLog;
	/**
	 * 订单金额
	 */
	private BigDecimal totalPrice;
	/**
	 * 订单总金额 :订单金额加上派送费
	 */
	private BigDecimal orderTotalPrice;
	/**
	 * 取餐金额
	 */
	private BigDecimal takeMealPrice;
	/**
	 * 订单明细
	 */
	private String detail;
	/**
	 * 客户名称
	 */
	private String custName;
	/**
	 * 客户电话
	 */
	private String telephone;
	/**
	 * 客户地址
	 */
	private String custAddress;

	/**
	 * 订单的经纬度位置
	 */
	private String custPosition;

	/**
	 * 配送备注
	 */
	private String note;
	/**
	 * 配送时间
	 */
	private java.util.Date deliveryTime;
	/**
	 * 支付方式
	 */
	private int payMethod;

	/**
	 * 是否需要保温
	 */
	private int needWarmBox;

	/** 创建时间 */
	private java.util.Date createDate;
	/** 创建人ID */
	private java.lang.String createBy;
	/** 创建人名称 */
	private java.lang.String createName;
	/** 修改时间 */

	private java.util.Date updateDate;
	/** 修改人ID */

	private java.lang.String updateBy;
	/** 修改人名称 */

	private java.lang.String updateName;

	/**
	 * 配送员姓名
	 */
	private String deliveryManName;
	/**
	 * 配送员ID
	 */
	private String deliveryManID;

	/**
	 * 店面
	 */
	private StorefrontVO storefrontEntity;

	/**
	 * 分配到的配送员
	 */
	private DeliveryManVO deliveryMan;

	/**
	 * 拒绝过这单的配送员ID列表中间用,隔开
	 */
	private String refuseDeliveryman;

	/**
	 * 区域ID
	 */
	private String regionID;

	/**
	 * 区域名称
	 */
	private String regionName;
	/**
	 * 归班
	 */
	private ReturnVO returnVO;
	/**
	 * 配送费用
	 */
	private BigDecimal deliveryPrice;
	/**
	 * 要求送达时间
	 */
	private Date askSendTime;
	/**
	 * 分配时间
	 */
	private Date distributeTime;
	/**
	 * 取餐时间
	 */
	private Date takeMealTime;
	/**
	 * 接受时间
	 */
	private Date acceptTime;
	/**
	 * 完成时间
	 */
	private Date completeTime;
	/**
	 * 订单取消内部原因备注
	 */
	private String insideCauseDesc;
	/**
	 * 订单取消外部原因备注
	 */
	private String outCauseDesc;

	/**
	 * 归班结算历史记录id
	 */
	private String returnRecordId;

	/**
	 * 是否已经结算派费 0:未结算，1：已结算
	 */
	private int isSettleDelivery;
	/**
	 * 派费结算记录ID，关联bd_SettleAccoutsRecord表主键
	 */
	private String settleRecordId;
	/**
	 * 备单状态，0：未备单，1：开始备单，2：备单完成
	 */
	private int readyStatus;
	/**
	 * 第三方单位要求加的列
	 */
	private int orderid;
	/**
	 * 额外奖励金额
	 */
	private int rewardprice;
	/**
	 * 配送员postmanId
	 */
	private Integer postmanId;
	/**
	 * 配送员姓名
	 */
	public String deliveryManPhone;
	/**
	 * 取消代码
	 */
	public Integer cancelCode;
	/**
	 * 取消原因
	 */
	public String cancelMsg;

	/**
	 * 发件人姓名
	 */
	public String senderName;

	/**
	 * 发件人电话
	 */
	public String senderPhone;

	/**
	 * 发件人地址
	 */
	public String senderAddress;


	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
	@Column(name = "ID", nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "order_id", nullable = false)
	public int getOrderid() {
		return orderid;
	}

	
	public void setOrderid(int orderid) {
		this.orderid = orderid;
	}
	
	@Column(name = "reward_price", columnDefinition = "decimal(12,2) default 0")
	public int getRewardprice() {
		return rewardprice;
	}

	public void setRewardprice(int rewardprice) {
		this.rewardprice = rewardprice;
	}
	
	@Column(name = "postman_id")
	public Integer getPostmanId() {
		return postmanId;
	}

	public void setPostmanId(Integer postmanId) {
		this.postmanId = postmanId;
	}
	
	@Column(name = "deliveryman_phone")
	public String getDeliveryManPhone() {
		return deliveryManPhone;
	}

	public void setDeliveryManPhone(String deliveryManPhone) {
		this.deliveryManPhone = deliveryManPhone;
	}

	@Column(name = "cancel_code")
	public Integer getCancelCode() {
		return cancelCode;
	}

	public void setCancelCode(Integer cancelCode) {
		this.cancelCode = cancelCode;
	}

	@Column(name = "cancelm_msg")
	public String getCancelMsg() {
		return cancelMsg;
	}

	public void setCancelMsg(String cancelMsg) {
		this.cancelMsg = cancelMsg;
	}

	@Column(name = "sender_name")
	public String getSenderName() {
		return senderName;
	}

	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}

	@Column(name = "sender_phone")
	public String getSenderPhone() {
		return senderPhone;
	}

	public void setSenderPhone(String senderPhone) {
		this.senderPhone = senderPhone;
	}

	@Column(name = "sender_address")
	public String getSenderAddress() {
		return senderAddress;
	}

	public void setSenderAddress(String senderAddress) {
		this.senderAddress = senderAddress;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "order_name")
	public String getOrderName() {
		return this.orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public int getStatus() {
		return this.status;
	}

	// 用于状态的显示
	@Transient
	public String getStatusText() {
		return OrderStatusEnum.getTextByValue(this.status);
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@Column(name = "status_change_time", columnDefinition = "datetime")
	public Date getStatusChangeTime() {
		return this.statusChangeTime;
	}

	public void setStatusChangeTime(Date statusChangeTime) {
		this.statusChangeTime = statusChangeTime;
	}

	@Column(name = "status_log", columnDefinition="longtext")
	public String getStatusLog() {
		return this.statusLog;
	}

	public void setStatusLog(String statusLog) {
		this.statusLog = statusLog;
	}

	@Column(name = "total_price", columnDefinition = "decimal(12,2) default 0")
	public BigDecimal getTotalPrice() {
		return this.totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

	@Column(name = "Order_Total_Price", columnDefinition = "decimal(12,2) default 0")
	public BigDecimal getOrderTotalPrice() {
		return this.orderTotalPrice;
	}

	public void setOrderTotalPrice(BigDecimal orderTotalPrice) {
		this.orderTotalPrice = orderTotalPrice;
	}

	@Column(name = "Take_Meal_Price", columnDefinition = "decimal(12,2) default 0")
	public BigDecimal getTakeMealPrice() {
		return this.takeMealPrice;
	}

	public void setTakeMealPrice(BigDecimal takeMealPrice) {
		this.takeMealPrice = takeMealPrice;
	}

	public static long getSerialversionuid() {
		return OrderVO.serialVersionUID;
	}

	public String getDetail() {
		return this.detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	@Column(name = "cust_name")
	public String getCustName() {
		return this.custName;
	}

	public void setCustName(String custName) {
		this.custName = custName;
	}

	public String getTelephone() {
		return this.telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Column(name = "cust_address")
	public String getCustAddress() {
		return this.custAddress;
	}

	public void setCustAddress(String custAddress) {
		this.custAddress = custAddress;
	}

	public String getNote() {
		return this.note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Column(name = "delivery_time", columnDefinition = "datetime")
	public java.util.Date getDeliveryTime() {
		return this.deliveryTime;
	}

	public void setDeliveryTime(java.util.Date deliveryTime) {
		this.deliveryTime = deliveryTime;
	}

	@Transient
	public String getDeliveryTimeStr() {
		return Tools.formatTime(this.deliveryTime, "yyyy-MM-dd hh:mm:ss");
	}

	@Column(name = "pay_method")
	public int getPayMethod() {
		return this.payMethod;
	}

	// 用于支付方式的显示
	@Transient
	public String getPayMethodText() {
		return OrderPayMethodEnum.getTextByValue(this.payMethod);
	}

	public void setPayMethod(int payMethod) {
		this.payMethod = payMethod;
	}

	@Column(name = "need_warm_box")
	public int getNeedWarmBox() {
		return this.needWarmBox;
	}

	@Transient
	public String getNeedWarmBoxText() {
		return YesNoEnum.getTextByValue(this.needWarmBox);
	}

	public void setNeedWarmBox(int needWarmBox) {
		this.needWarmBox = needWarmBox;
	}

	@Column(name = "create_date", columnDefinition = "datetime")
	public java.util.Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(java.util.Date createDate) {
		this.createDate = createDate;
	}

	@Column(name = "create_by")
	public java.lang.String getCreateBy() {
		return this.createBy;
	}

	public void setCreateBy(java.lang.String createBy) {
		this.createBy = createBy;
	}

	@Column(name = "create_name")
	public java.lang.String getCreateName() {
		return this.createName;
	}

	public void setCreateName(java.lang.String createName) {
		this.createName = createName;
	}

	@Column(name = "update_date", columnDefinition = "datetime")
	public java.util.Date getUpdateDate() {
		return this.updateDate;
	}

	public void setUpdateDate(java.util.Date updateDate) {
		this.updateDate = updateDate;
	}

	@Column(name = "update_by")
	public java.lang.String getUpdateBy() {
		return this.updateBy;
	}

	public void setUpdateBy(java.lang.String updateBy) {
		this.updateBy = updateBy;
	}

	@Column(name = "update_name")
	public java.lang.String getUpdateName() {
		return this.updateName;
	}

	public void setUpdateName(java.lang.String updateName) {
		this.updateName = updateName;
	}

	@Column(length = 32, name = "returnRecord_Id")
	public String getReturnRecordId() {
		return this.returnRecordId;
	}

	public void setReturnRecordId(String returnRecordId) {
		this.returnRecordId = returnRecordId;
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "storefront_id")
	public StorefrontVO getStorefrontEntity() {
		return this.storefrontEntity;
	}

	@Transient
	public String getStorefrontName() {
		if (this.storefrontEntity != null) {
			return this.storefrontEntity.getStoName();
		} else {
			return "";
		}
	}

	@Transient
	public String getStorefrontID() {
		if (this.storefrontEntity != null) {
			return this.storefrontEntity.getId();
		} else {
			return "";
		}
	}

	@Transient
	public String getStoreAddress() {
		if (this.getStorefrontEntity() != null) {
			return this.storefrontEntity.getStoAddress();
		} else {
			return "";
		}
	}

	@Transient
	public String getStorefrontCoordinate() {
		if (this.storefrontEntity != null) {
			return this.storefrontEntity.getStoCoordinate();
		} else {
			return "";
		}
	}

	public void setStorefrontEntity(StorefrontVO storefrontEntity) {
		this.storefrontEntity = storefrontEntity;
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "deliveryman_id")
	public DeliveryManVO getDeliveryMan() {
		return this.deliveryMan;
	}

	@Column(name = "deliveryman_name")
	public String getDeliveryManName() {
		return this.deliveryManName;
	}
	
	public void setDeliveryManName(String deliveryManName) {
		this.deliveryManName = deliveryManName;
	}

	@Transient
	public String getDeliveryManID() {
		if (this.deliveryMan != null) {
			return this.deliveryMan.getId();
		} else {
			return this.deliveryManID;
		}
	}

	public void setDeliveryManID(String deliveryManID) {
		if (this.deliveryMan != null) {
			this.deliveryMan.setId(deliveryManID);
		}
		this.deliveryManID = deliveryManID;
	}

	public void setDeliveryMan(DeliveryManVO deliveryMan) {
		this.deliveryMan = deliveryMan;
	}

	@Column(name = "refuse_deliveryman")
	public String getRefuseDeliveryman() {
		return this.refuseDeliveryman;
	}

	public void setRefuseDeliveryman(String refuseDeliveryman) {
		this.refuseDeliveryman = refuseDeliveryman;
	}

	@Column(name = "cust_position")
	public String getCustPosition() {

		// 暂时返回一个固定值
		// return "{\"lng\":116.34453434,\"lat\":39.7898987}";
		return this.custPosition;
	}

	public void setCustPosition(String custPosition) {
		this.custPosition = custPosition;
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "return_id")
	public ReturnVO getReturnVO() {
		return this.returnVO;
	}

	public void setReturnVO(ReturnVO returnVO) {
		this.returnVO = returnVO;
	}

	@Column(name = "Delivery_Price", columnDefinition = "decimal(12,2) default 0")
	public BigDecimal getDeliveryPrice() {
		return this.deliveryPrice;
	}

	public void setDeliveryPrice(BigDecimal deliveryPrice) {
		this.deliveryPrice = deliveryPrice;
	}

	@Column(name = "ask_send_time", columnDefinition = "datetime")
	public Date getAskSendTime() {
		return this.askSendTime;
	}

	public void setAskSendTime(Date askSendTime) {
		this.askSendTime = askSendTime;
	}

	@Column(name = "take_meal_Time", columnDefinition = "datetime")
	public Date getTakeMealTime() {
		return this.takeMealTime;
	}

	public void setTakeMealTime(Date takeMealTime) {
		this.takeMealTime = takeMealTime;
	}

	@Column(name = "accept_Time", columnDefinition = "datetime")
	public Date getAcceptTime() {
		return this.acceptTime;
	}

	public void setAcceptTime(Date acceptTime) {
		this.acceptTime = acceptTime;
	}

	@Column(name = "complete_Time", columnDefinition = "datetime")
	public Date getCompleteTime() {
		return this.completeTime;
	}

	public void setCompleteTime(Date completeTime) {
		this.completeTime = completeTime;
	}

	@Column(name = "Distribute_Time", columnDefinition = "datetime")
	public Date getDistributeTime() {
		return this.distributeTime;
	}

	public void setDistributeTime(Date distributeTime) {
		this.distributeTime = distributeTime;
	}

	@Column(length = 500, name = "Inside_Cause_Desc")
	public String getInsideCauseDesc() {
		return this.insideCauseDesc;
	}

	public void setInsideCauseDesc(String insideCauseDesc) {
		this.insideCauseDesc = insideCauseDesc;
	}

	@Column(length = 500, name = "Out_Cause_Desc")
	public String getOutCauseDesc() {
		return this.outCauseDesc;
	}
	
	public void setOutCauseDesc(String outCauseDesc) {
		this.outCauseDesc = outCauseDesc;
	}

	@Column(name = "is_Settle_Delivery", columnDefinition = "int default 0")
	public int getIsSettleDelivery() {
		return this.isSettleDelivery;
	}

	public void setIsSettleDelivery(int isSettleDelivery) {
		this.isSettleDelivery = isSettleDelivery;
	}

	@Column(length = 32, name = "settleRecord_Id")
	public String getSettleRecordId() {
		return this.settleRecordId;
	}

	public void setSettleRecordId(String settleRecordId) {
		this.settleRecordId = settleRecordId;
	}

	@Transient
	public String getIsSettleDeliveryStr() {
		return OrderIsSettleDeliveryEnum.getTextByValue(this.getIsSettleDelivery());
	}

	@Transient
	public String getRegionID() {
		return this.regionID;
	}

	public void setRegionID(String regionID) {
		this.regionID = regionID;
	}

	@Transient
	public String getRegionName() {
		return this.regionName;
	}

	public void setRegionName(String regionName) {
		this.regionName = regionName;
	}

	@Column(name = "ready_Status", columnDefinition = "int default 0")
	public int getReadyStatus() {
		return this.readyStatus;
	}

	public void setReadyStatus(int readyStatus) {
		this.readyStatus = readyStatus;
	}

	@Transient
	public String getReadyStatusStr() {
		return OrderReadyStatus.getText(this.getReadyStatus());
	}
	
	/**
	 *
	 * @Title: getFoodDetail
	 * @Description: 获取详情中的菜品、数量、价格
	 * @author 孟凡岭
	 * @param @return
	 * @return List<Map<String,String>> 返回类型
	 * @throws
	 */
	/*
	@Transient
	public List<Map<String, String>> getFoodDetail() {
		String[] arr = this.detail.split("&&&");
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (String string : arr) {
			Map<String, String> map = new HashMap<String, String>();
			String[] arr2 = string.trim().split("\\^|￥");
			map.put("food", arr2[0]);
			map.put("count", arr2[1]);
			map.put("money", arr2[2]);
			list.add(map);
		}
		return list;
	}
	*/
}
